﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CtCache;
using CtCommon.Utility;
using Cxx.BLL;
using Cxx.Common;
using Cxx.Entity;

namespace Cxx.OrderManagerSys
{
    public partial class StockExport : System.Web.UI.Page
    {
        public string name;

        protected void Page_Load(object sender, EventArgs e)
        {
            name = WebHelper.GetQueryString("name");
            if (Request.HttpMethod == "POST")
            {
                if (string.IsNullOrEmpty(name))
                {
                    Response.Write("没有可导出的内容");
                    Response.End();
                    return;
                }
                List<StockInfo> list = Stock.Get(name);
                if (list == null || list.Count == 0)
                {
                    JScript.Alert(Page, "没有可导出的内容");
                    return;
                }
                string[] columnNames =
                {
                    "编号", "单位", "商品名称", "库存数量"
                };

                var table = TableHelper.GetDataTable(list, columnNames);

                AsposeExcelHelper.GetInstance()
                    .ExportToWeb("澳门库存赌本-" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls",
                        new Dictionary<string, DataTable> {{name + "的库存", table}});

            }
        }
    }
}